# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=LibRaw
pkgbase=mingw-w64-libraw
pkgname="${MINGW_PACKAGE_PREFIX}-libraw"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.17.1
pkgrel=1
pkgdesc="Library for reading RAW files obtained from digital photo cameras (mingw-w64)"
arch=('any')
url="http://www.libraw.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-jasper")
options=('staticlibs' 'strip')
source=("http://www.libraw.org/data/${_realname}-${pkgver}.tar.gz"
        "http://www.libraw.org/data/${_realname}-demosaic-pack-GPL2-${pkgver}.tar.gz"
        "http://www.libraw.org/data/${_realname}-demosaic-pack-GPL3-${pkgver}.tar.gz"
        "LibRaw_wsock32.patch"
        "LibRaw_obsolete-macros.patch")
sha256sums=('e599651a4cc37e00cfc2d2b56be87c3a4e4dae2c360b680fe9ab3f93d07cdea1'
            '2e9f72873a6db319aca5be5bc4d426e3063e2c33f66438e89720c3b48bef0678'
            '442b3e8de4664e539cbcdd437a7b6cd167e07c0fcf76f07b50d16657f18ff962'
            '4bd077917fb8f37fa736e3a8bf32fabe3df3ff5438b684acbb5adff8a6c2a73b'
            '4a31c0ee066f43915beff6f7959b6b2cd246d390720df379bfc047d4cedb6a8f')

prepare() {
  mv ${srcdir}/${_realname}-demosaic-pack-GPL2-${pkgver} ${srcdir}/${_realname}-$}pkgver}/
  mv ${srcdir}/${_realname}-demosaic-pack-GPL3-${pkgver} ${srcdir}/${_realname}-${pkgver}/
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/LibRaw_wsock32.patch"
  patch -Np1 -i "${srcdir}/LibRaw_obsolete-macros.patch"

  autoreconf -ifv
}

build() {
  CPPFLAGS+=" -DLIBRAW_NODLL"
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --enable-jasper \
      --enable-lcms \
      --enable-demosaic-pack-gpl2 \
      --enable-demosaic-pack-gpl3

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
